/**
 * Created by wlc on 2018/9/11.
 */

/**
 * 全局变量
 */
//markdown
var writeEditor;

//notice
var notyf;

/**
 * 变量与对象初始化
 */
window.onload = function (){
    //通知栏
    notyf = new Notyf();
};

/**
 * 文章内容发表
 */
$(document).on("click",'#textSubmit', function(e){
    var evt=e||window.event;               //保证兼容性
    var tar=evt.target||evt.srcElement;  //获取触发事件的元素

    var id = $('#hidden-fileId')[0].value;   //可以为空
    var title = $('#textTitle')[0].value;
    var type = $('#textType')[0].value;
    var content = writeEditor.getValue().replace(/\n/g,'\\n').replace(/"/g,'\\"').replace(/'/g,"\\'");

    if (!isEmpty(title)){
        if (!isEmpty(content)){
            if (type !== "(无)"){
                window.location.href = '../fileManager/submitFile?id='+encodeURIComponent(id)+'&title='+encodeURIComponent(title)+'&type='+encodeURIComponent(type)+'&content='+encodeURIComponent(content);
            }else {
                notyf.alert("文章类型不能为空！");
            }
        }else {
            notyf.alert("文章内容不能为空！");
        }
    }else {
        notyf.alert("文章标题不能为空！");
    }
});
